package com.nb82.bean.im.pro;

import java.io.Serializable;

public class PackageHead implements Serializable {
	private static PackageHead head = new PackageHead();
	private static final long serialVersionUID = 3965541808116510722L;
	private int id; // id
	private int packageHeadLength; // 协议头长度
	private int messageType; // 消息类型
	private int contentType; // 头类型
	private int messageCommand; // 消息命令
	private int packageBodyLength; // 消息体长度
	private String packageBodyContent; // packageBodyLength

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getPackageHeadLength() {
		return packageHeadLength;
	}

	public void setPackageHeadLength(int packageHeadLength) {
		this.packageHeadLength = packageHeadLength;
	}

	public int getMessageType() {
		return messageType;
	}

	public void setMessageType(int messageType) {
		this.messageType = messageType;
	}

	public int getContentType() {
		return contentType;
	}

	public void setContentType(int contentType) {
		this.contentType = contentType;
	}

	public int getMessageCommand() {
		return messageCommand;
	}

	public void setMessageCommand(int messageCommand) {
		this.messageCommand = messageCommand;
	}

	public int getPackageBodyLength() {
		return packageBodyLength;
	}

	public void setPackageBodyLength(int packageBodyLength) {
		this.packageBodyLength = packageBodyLength;
	}

	public String getPackageBodyContent() {
		return packageBodyContent;
	}

	public void setPackageBodyContent(String packageBodyContent) {
		this.packageBodyContent = packageBodyContent;
	}

	@Override
	public String toString() {
		return "Messeage is: command=" + getMessageCommand() + ", type="
				+ getMessageType() + ", contentLength="
				+ getPackageBodyLength() + ", content="
				+ getPackageBodyContent();
	}
	public static PackageHead createHartRequest(String msg){
		head.setPackageHeadLength(10);
		head.setMessageType(MessageType.HEART_BEAT);
		head.setContentType(MessageType.MESSAGE_TYPE_PUSH);
		head.setPackageBodyLength(msg.getBytes().length);
		head.setPackageBodyContent(msg);
		return head;
	}
	public static PackageHead createHartResponse(String msg){
		head.setPackageHeadLength(10);
		head.setMessageType(MessageType.HEART_BEAT_ACK);
		head.setContentType(MessageType.MESSAGE_TYPE_REQUEST);
		head.setPackageBodyLength(msg.getBytes().length);
		head.setPackageBodyContent(msg);
		return head;
	}
	
	public static PackageHead create(int messageType,int contentType,String msg){
		head.setPackageHeadLength(10);
		head.setMessageType(messageType);
		head.setContentType(contentType);
		head.setPackageBodyLength(msg.getBytes().length);
		head.setPackageBodyContent(msg);
		return head;
	}
}